package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.MyNotice;
import com.hs.service.MyNoticeService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("mynotice")
public class MyNoticeController {
    @Autowired
    private MyNoticeService myNoticeService;
    @PostMapping
    public R addMyNotice(@RequestBody MyNotice myNotice) {
        int i = myNoticeService.addMyNotice(myNotice);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @PutMapping
    public R updateMyNotice(@RequestBody MyNotice myNotice) {
        int i = myNoticeService.updateMyNotice(myNotice);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @DeleteMapping("{id}")
    public R deleteMyNotice(@PathVariable("id") int id) {
        int i = myNoticeService.deleteMyNotice(id);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @GetMapping("{id}")
    public R getMyNotice(@PathVariable("id") int id) {
        List<MyNotice> myNotice = myNoticeService.getMyNoticeById(id);
        return R.ok(myNotice);
    }
    @GetMapping("page")
    public R getMyNoticePage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                             @RequestParam(required = false,defaultValue = "2") int pageSize) {
        PageInfo<MyNotice> myNoticeByPage = myNoticeService.getMyNoticeByPage(pageNum, pageSize);
        return R.ok(myNoticeByPage);
    }
}
